package cn.itlight.feignclient;

import cn.itlight.entity.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {
    @Override
    public UserFeignClient create(Throwable throwable) {
        //返回UserFeignClient 接口的实例
        return new UserFeignClient() {
            @Override
            public User getById(Long id) {
                //把异常信息打印到控制台
                throwable.printStackTrace();

                //真正拖地方法 ， 这里的数据是托底数据
                return new User(-1L,"无此用户","用户服务不可用");
            }
        };
    }
}
